package com.qzsoft.zhjd.materiel.modules.materielapi.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.qzsoft.zhjd.materiel.modules.materielapi.service.MaterielApiVesionService;

/**
 * @ClassName ClientApiUpdateAspect
 * @Description 客户端接口切面
 * @author linhuawei
 * @since 2021-12-11
 */
@Aspect
@Component
public class MaterielApiUpdateAspect {

    @Autowired
    private MaterielApiVesionService materielApiVesionService;

    @Pointcut("@annotation(com.qzsoft.zhjd.materiel.modules.materielapi.aop.MaterielApiUpdate)")
    public void pointCut() {
    }

    @Pointcut("execution(* com.qzsoft.jeemis.platform.dict.controller.BasicCodeEditController.saveCodeCollect(..)) || "
            + "execution(* com.qzsoft.jeemis.platform.dict.controller.BasicCodeEditController.saveCodeItem(..)) || "
            + "execution(* com.qzsoft.jeemis.platform.dict.controller.BasicCodeEditController.deleteSysCodeItem(..)) || "
            + "execution(* com.qzsoft.jeemis.platform.dict.controller.BasicCodeEditController.deleteSysCodeCollect(..))")
    public void pointCutDict() {
    }

    @Before("pointCut() && @annotation(materielApiUpdate)")
    public void doBefore(JoinPoint point, MaterielApiUpdate materielApiUpdate) {
        if (null != materielApiUpdate) {
            String code = materielApiUpdate.value();
            if (ObjectUtils.isNotEmpty(code)) {
                materielApiVesionService.updateByCode(code);
            }
        }
    }

    /**
     * @Title doBeforeDict
     * @Description 字典变化，更新过磅类型数据
     * @param point
     */
    @Before("pointCutDict()")
    public void doBeforeDict(JoinPoint point) {
        materielApiVesionService.updateByCode("getWeightType");
    }

}
